package com.rmuti.acm.string;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class CDR {

	public static void main(String[] args) {
		try {
			Scanner sc = new Scanner(new File("C:/Users/off/git/rmuti-programming-lab/javapattern/src/test.in"));
			String cfg = sc.nextLine();
			String [] arrCfg = cfg.split(" ");
			int numLine = Integer.parseInt(arrCfg[0]);
			int numCDR = Integer.parseInt(arrCfg[1]);
			String strOut = "";
			for (int i = 0; i < numLine; i++) {
				String dataLine = sc.nextLine();
				String[] arrDataLine = dataLine.split(" ");
				strOut = arrDataLine[0];
				if(arrDataLine.length-1 > numCDR){
					strOut += " "+arrDataLine[numCDR+1];
				} else {
					int sum = 0;
					for(int j=1;j<arrDataLine.length;j++){
						sum+=Integer.parseInt(arrDataLine[j]);
					}
					strOut+=" "+sum;
				}
				System.out.println(strOut);
			}
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
	}
}
